Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_packet/target_posix/roc_packet/address.h
10//! @brief Network address.
11
12#ifndef ROC_PACKET_ADDRESS_H_
13#define ROC_PACKET_ADDRESS_H_
14
15#include <netinet/in.h>
16#include <sys/socket.h>
17
18#include "roc_core/stddefs.h"
19
20namespace roc {
21namespace packet {
22
23//! Network address.
24class Address {
25public:
26 //! Construct invalid address.
28
29 //! Check if the address was properly initialized.
30 bool valid() const;
31
32 //! Set address from sockaddr struct.
33 bool set_saddr(const sockaddr* sa);
34
35 //! Set IPv4 address.
36 bool set_ipv4(const char* ip, int port);
37
38 //! Set IPv6 address.
39 bool set_ipv6(const char* ip, int port);
40
41 //! Get sockaddr struct.
42 sockaddr* saddr();
43
44 //! Get sockaddr struct.
45 const sockaddr* saddr() const;
46
47 //! Get sockaddr struct length.
48 socklen_t slen() const;
49
50 //! Get IP version (4 or 6).
51 int version() const;
52
53 //! Get address port.
54 int port() const;
55
56 //! Check whether this is multicast address.
57 bool multicast() const;
58
59 //! Get IP address.
60 bool get_ip(char* buf, size_t bufsz) const;
61
62 //! Compare addresses.
63 bool operator==(const Address& other) const;
64
65 //! Compare addresses.
66 bool operator!=(const Address& other) const;
67
68private:
69 static socklen_t sizeof_(sa_family_t family);
70
71 sa_family_t family_() const;
72
73 union {
74 sockaddr_in addr4;
75 sockaddr_in6 addr6;
76 } sa_;
77};
78
79} // namespace packet
80} // namespace roc
81
82#endif // ROC_PACKET_ADDRESS_H_
Network address.
Definition: address.h:24
bool set_ipv4(const char *ip, int port)
Set IPv4 address.
bool operator==(const Address &other) const
Compare addresses.
Address()
Construct invalid address.
bool set_ipv6(const char *ip, int port)
Set IPv6 address.
bool valid() const
Check if the address was properly initialized.
int port() const
Get address port.
bool operator!=(const Address &other) const
Compare addresses.
sockaddr * saddr()
Get sockaddr struct.
const sockaddr * saddr() const
Get sockaddr struct.
bool set_saddr(const sockaddr *sa)
Set address from sockaddr struct.
socklen_t slen() const
Get sockaddr struct length.
bool multicast() const
Check whether this is multicast address.
bool get_ip(char *buf, size_t bufsz) const
Get IP address.
int version() const
Get IP version (4 or 6).
Root namespace.
Commonly used types and functions.